<template>
	<view  >   
		 <Chart ></Chart>
		 <Chart ></Chart>
	</view>
</template>

<script>
	// 图表
	import uCharts from "@/components/u-charts/u-charts.js";
	var that;
	import Chart from '@/components/analysis/analysis'
	import mInit from '../../../tools/Init';
	var canvaRing = null; 
	var ERShoopManage = require('../../../service/ERShoopManage.js'),
		mERShoopManage;
	var UserInfo = require('../../../service/UserInfo.js'),
		mUserInfo;
	var ERgoodsShelf = require('../../../service/ERgoodsShelf'),
		mERgoodsShelf;
	var ERGoodsScan = require('../../../service/ERGoodsScan'),
		mERGoodsScan;
	export default {
		components:{
			Chart
		},
		data() {
			return { 
			 
			};
		},
		onLoad() {
			that = this; 
			console.log('this的指向',this)
			mERShoopManage = new ERShoopManage(this.mNetTool);
			mERgoodsShelf = new ERgoodsShelf(this.mNetTool);
			mERGoodsScan = new ERGoodsScan(this.mNetTool);
			this.cWidth = uni.upx2px(750);
			this.cHeight = uni.upx2px(420);
			 
			mInit.init(this.mNetTool, res => {
			let userInfo = uni.getStorageSync('userInfo');
			if (userInfo) {
			 this.loadData();
			}else{
				//未登录
			}
			 
		});
		},
		computed: {

		},
		mounted() {

		},
		methods: {
			loadData(){
				that.getgoods()
			},
			filterByTime(){
				
			},
			getShop(){
				//137
			},
			getAnaisy(arr){ 
				let list = []
				list = arr
				let all = arr.length
				let nowTime = new Date().getTime()//当前时间戳
				 
				let err = [] //没有过期时间的商品 
				let no_overdue = [] //没过去
				let will_overdue= [] //快要过期（1个月内
				let to_overdue= [] //即将过期 （一个星期内
				let is_overdue= [] //已经过期 
				for(let i =0;i<list.length;i++){
					if(list[i].expiration_date && list[i].expiration_date < nowTime){
						//已经过期
						is_overdue.push(list[i])
					 
					}else if(list[i].expiration_date && list[i].expiration_date > nowTime && list[i].expiration_date < nowTime + 1000*60*60*24*7){
						// 快要过期
						will_overdue.push(list[i])
					}else if(list[i].expiration_date && list[i].expiration_date > nowTime && list[i].expiration_date < nowTime + 1000*60*60*24*30){
						// 即将过期
						to_overdue.push(list[i])
					}else if(list[i].expiration_date && list[i].expiration_date > nowTime){
						// 即将过期
						no_overdue.push(list[i])
					}else{
						err.push(list[i])
					}
				}
				console.log('err',err)
				console.log('is_overdue',is_overdue)
				console.log('will_overdue',will_overdue)
				console.log('to_overdue',to_overdue)
				console.log('no_overdue',no_overdue)
				// let errNum = parseInt(all/err.length)
				// let isOverdueNum = parseInt(all/is_overdue.length)
				// let willOverdueNum = parseInt(all/will_overdue.length)
				// let toOverdueNum = parseInt(all/to_overdue.length)
				// let noOverdueNum = parseInt(all/no_overdue.length)
				let series = [{
						"name": "异常",
						"data": err.length,
					},{
						"name": "未过期",
						"data": no_overdue.length,
					}, {
						"name": "快过期",
						"data": will_overdue.length
					}, {
						"name": "临期",
						"data": to_overdue.length
					}, {
						"name": "已过期",
						"data": is_overdue.length
					}]
					console.log(series)
			},
			//获取商品
			getgoods(){
				mERGoodsScan.list({
					own_store_id: 137,
				},res=>{
					console.log('当前店铺所以东西',res)
					if(res.records > 0){
						that.getAnaisy(res.rows)
					}
				})
			},
			 
 

		}
	};
</script>

<style lang="scss" scoped>
	.chartsMain {
		width: 750rpx;
		height: 450rpx;
		padding-top: 15rpx;
		background: #fff;
		margin-bottom: 24rpx;
		border-top: 2rpx solid #f2f2f2;
		.charts {
			width: 750rpx;
			height: 450rpx;
			box-sizing: border-box;
		}
	}
</style>
